﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LuZhouLaoJiao
{
    public partial class SetRemoteDB : Form
    {
        public SetRemoteDB()
        {
            InitializeComponent();
        }

        private void btnRemoteFinish_Click(object sender, EventArgs e)
        {
            string tbRemoteIPstr = tbRemoteIP.Text.ToString();
            string tbRemoteDBUserstr = tbRemoteDBUser.Text.ToString();
            string tbRemoteDBPwdstr = tbRemoteDBPwd.Text.ToString();
            string tbRemoteDBPwd2str = tbRemoteDBPwd2.Text.ToString();
            string tbRemoteDatabasestr = tbRemoteDB.Text.ToString();

            if (tbRemoteIPstr.Equals("") || tbRemoteDBUserstr.Equals("") || tbRemoteDBPwdstr.Equals("") || tbRemoteDatabasestr.Equals(""))
            {
                MessageBox.Show("所有信息均为必填！");
            }
            else
            {
                if (!Global.IsIP(tbRemoteIPstr))
                {
                    MessageBox.Show("输入的不是合法的IP地址！");
                }
                else if (tbRemoteDBPwdstr != tbRemoteDBPwd2str)
                {
                    MessageBox.Show("密码输入不一致！");
                }
                else
                {
                    Global.setRegeditValue("remoteIP", tbRemoteIPstr);
                    Global.setRegeditValue("remoteDBUser", tbRemoteDBUserstr);
                    Global.setRegeditValue("remoteDBPwd", tbRemoteDBPwdstr);
                    Global.setRegeditValue("remoteDatabase", tbRemoteDatabasestr);

                    Global.setRegeditValue("AlreadySetRemoteDB", "YES");

                    this.Close();
                }
            }
        }

        private void SetRemoteDB_Load(object sender, EventArgs e)
        {
            Global.setRegeditValue("AlreadyRunSetRemoteDB", "YES");
        }
    }
}
